<html>
<head>
<link rel="shortcut icon" href="./favicon.ico">
<link rel="stylesheet" type="text/css" href="./style.css">
<link rel="canonical" href="./Multiplexer_Bitwise_2to1.html">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Selects each bit from one of two input words, based on a bitmask of the same width. For each bitmask bit, 0 selects the corresponding bit from word_in_0, and 1 selects from word_in_1.">
<title>Multiplexer Bitwise 2to1</title>
</head>
<body>

<p class="inline bordered"><b><a href="./Multiplexer_Bitwise_2to1.v">Source</a></b></p>
<p class="inline bordered"><b><a href="./legal.html">License</a></b></p>
<p class="inline bordered"><b><a href="./index.html">Index</a></b></p>

<h1>Bitwise 2:1 Multiplexer</h1>
<p>Selects each bit from one of two input words, based on a bitmask of the
 same width. For each bitmask bit, 0 selects the corresponding bit from
 word_in_0, and 1 selects from word_in_1.</p>
<p>This function may look trivial, but it implements the important and useful
 Shannon Decomposition, originally known as Boole's Expansion Theorem, which
 allows you to compose smaller Boolean functions of N variables into
 a larger one of N+1 variables.</p>

<pre>
`default_nettype none

module <a href="./Multiplexer_Bitwise_2to1.html">Multiplexer_Bitwise_2to1</a>
#(
    parameter WORD_WIDTH = 0
)
(
    input   wire    [WORD_WIDTH-1:0]    bitmask,
    input   wire    [WORD_WIDTH-1:0]    word_in_0,
    input   wire    [WORD_WIDTH-1:0]    word_in_1,
    output  wire    [WORD_WIDTH-1:0]    word_out
);

    generate
        genvar j;
        for(j = 0; j < WORD_WIDTH; j = j+1) begin: per_bit
            <a href="./Multiplexer_Binary_Behavioural.html">Multiplexer_Binary_Behavioural</a>
            #(
                .WORD_WIDTH     (1),
                .ADDR_WIDTH     (1),
                .INPUT_COUNT    (2)
            )
            bitwise
            (
                .selector       (bitmask[j]),    
                .words_in       ({word_in_1[j],word_in_0[j]}),
                .word_out       (word_out[j])
            );
        end
    endgenerate

endmodule
</pre>

<hr>
<p><a href="./index.html">Back to FPGA Design Elements</a>
<center><a href="https://fpgacpu.ca/">fpgacpu.ca</a></center>
</body>
</html>

